#include "StdAfx.h"
#include "XmlConfig.h"


XmlConfig::XmlConfig(void)
{
}


XmlConfig::~XmlConfig(void)
{
}

bool XmlConfig::Open(char * filename)
{
	if (_Doc.LoadFile(filename) == false)
		return false;

	return true;
}

bool XmlConfig::TransferString(char * pathvarname, char * link, size_t size, TransferMode mode)
{
	char * token;
	char * temp;
	char copy[XML_CONFIG_MAX_VAR_LENGTH];

	strcpy_s(copy, XML_CONFIG_MAX_VAR_LENGTH, pathvarname);

	// head laden
	TiXmlElement * el = _Doc.FirstChildElement();
	if (el == NULL)
		return false;
	token = strtok_s(copy, "/", &temp);
	while (token != NULL)
	{
		el = el->FirstChildElement(token);
		if (el == NULL)
			return false;
		token = strtok_s(NULL, "/", &temp);
	}
	if (el == NULL)
		return false;
	strcpy_s(link, size, el->GetText());
	return true;
}

bool XmlConfig::TransferInteger(char * pathvarname, int * link, TransferMode mode)
{
	char temp[XML_CONFIG_MAX_VAR_LENGTH];

	if (link == NULL)
		return false;

	if (TransferString(pathvarname, temp, XML_CONFIG_MAX_VAR_LENGTH, mode) == false)
		return false;

	*link = atoi(temp);
	return true;
}

